<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';

const countdown = ref(3);
const router = useRouter();

const redirectToLogin = () => {
  router.push('/login');
};

onMounted(() => {
  const timer = setInterval(() => {
    countdown.value -= 1;
    if (countdown.value === 0) {
      clearInterval(timer);
      router.push('/login'); // 倒计时结束后跳转到登录页面
    }
  }, 1000);

  onBeforeUnmount(() => {
    clearInterval(timer);
  });
});
</script>

<template>
  <div class="registrationSuccessContainer">
    <div class="header">
      <img src="@/assets/1.jpg" alt="智链iLink" class="logo">
      <h1 style="color:white;margin-left:-34.375rem;">
        智链iLink
      </h1>
    </div>
    <div class="content">
      <img src="@/assets/success.png" alt="Success" class="successImage">
      <h1>注册成功!</h1>
      <p>{{ countdown }}s 后自动跳转...</p>
      <button class="useNowButton" @click="redirectToLogin">
        立即使用
      </button>
    </div>
  </div>
</template>

<style scoped>
:root {
  font-size: 16px;
}

.registrationSuccessContainer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #ffffff;
}

.header {
  display: flex;
  align-items: center;
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
}

.logo {
  height: 2.25rem;
  margin-top: 1.25rem;
  margin-left: 1.25rem;
}

.content {
  text-align: center;
}

.successImage {
  width: 25.125rem;
  height: auto;
  margin-top: 0%;
}

h1 {
  font-size: 1.875rem;
  margin-top: 0;
  font-weight: 600;
}

p {
  font-size: 1.125rem;
  color: #6b6b6b;
  margin-top: 5rem;
}

.useNowButton {
  background-color: #6698ff;
  color: white;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 0.3125rem;
  font-size: 1.5625rem;
  cursor: pointer;
  margin-top: 0;
  transition: background-color 0.3s;
  height: 3.75rem;
  width: 21.75rem;
}

.useNowButton:hover {
  background-color: #0056b3;
}
</style>
